#include "MoveCmd.h"
#include "../model/UMLObject.h"

#include <stdexcept>

MoveCmd::MoveCmd(UMLObject* target, const QPoint& pos)
:	Command(),
	_executed(false),
	_target(target),
	_pos(pos)
{
}

UMLObject* MoveCmd::target() const
{
	return _target;
}

QPoint MoveCmd::pos() const
{
	return _pos;
}

void MoveCmd::setPos(QPoint pos)
{
	_pos = pos;
}

void MoveCmd::execute()
{
	if (!_executed)
		_previous = _target->position();

	_target->setPosition(_pos);

	_executed = true;
}

void MoveCmd::unexecute()
{
	if (!_executed)
		return;

	_target->setPosition(_previous);

	_executed = false;
}

const char* MoveCmd::name() const
{
	return "MoveCmd";
}

